import regex from "@/plugins/regex";
/**domin */
export const initDomainFrom = {
  webDomain: "",
  sbcInIpvFour: "",
  sbcOutIpvFour: "",
  sbcInIpvSix: "",
  sbcOutIpvSix: "",
  email: "",
  isTransport: false,
};
/**rtp */
export const initRtpFrom = {
  rtpPortStart: "",
  rtpPortEnd: "",
};
/**dns */
export const initDnsFrom = {
  primaryDns: "",
  secondaryDns: "",
};
/**正则验证 */
const validateIpvFour = (multiLanguages: any) => {
  return (rule: any, value: string, callback: any) => {
    if (regex.ipv4.test(value)) {
      callback();
    } else {
      callback(new Error(multiLanguages("warning.field_input_error")));
    }
  };
};
const validateIpvSix = (multiLanguages: any) => {
  return (rule: any, value: string, callback: any) => {
    if (regex.ipv6.test(value)) {
      callback();
    } else {
      callback(new Error(multiLanguages("warning.field_input_error")));
    }
  };
};
const validateEmail = (multiLanguages: any) => {
  return (rule: any, value: string, callback: any) => {
    if (regex.email.test(value)) {
      callback();
    } else {
      callback(new Error(multiLanguages("warning.field_input_error")));
    }
  };
};
/**验证domain */
export const checkDomain = (multiLanguages: any) => {
  return {
    webDomain: [{ required: true, message: multiLanguages("warning.account_not_empty"), trigger: "change" }],
    sbcInIpvFour: [
      { required: true, message: multiLanguages("warning.password_not_empty"), trigger: "change" },
      { validator: validateIpvFour(multiLanguages), trigger: "change" },
    ],
    sbcOutIpvFour: [{ validator: validateIpvFour(multiLanguages), trigger: "change" }],
    sbcInIpvSix: [{ validator: validateIpvSix(multiLanguages), trigger: "change" }],
    sbcOutIpvSix: [{ validator: validateIpvSix(multiLanguages), trigger: "change" }],
    email: [{ validator: validateEmail(multiLanguages), trigger: "change" }],
  };
};
/**验证rtp */
export const checkRtp = (multiLanguages: any) => {
  return {
    rtpPortStart: [{ required: true, message: multiLanguages("warning.password_not_empty"), trigger: "change" }],
    rtpPortEnd: [{ required: true, message: multiLanguages("warning.password_not_empty"), trigger: "change" }],
  };
};
